package no.ntnu.fp.su.util;

/**
 * Generation of independent normal variates with Box Muller. [0]
 * 
 * [0] http://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
 */
public class NormalDistribution {
	public static double sample(double mean, double stdev) {
			double u1 = Math.random();
			double theta = 2.0*Math.PI*u1;
			double u2 = Math.random();
			double e = -1.0*Math.log(u2);
			double r = Math.sqrt(2.0*e);
			double value = r*Math.cos(theta);
			return stdev*value+mean;
	}
}
